package com.atguigu.gmall.realtime.util;

import com.atguigu.gmall.realtime.common.Constant;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author lzc
 * @Date 2023/2/21 11:33
 */
public class RedisUtil {
    
    private static Jedis jedis;
    
    private static JedisPool pool;
    
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setTestOnCreate(true);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        config.setMaxTotal(100);
        config.setMaxIdle(10);
        config.setMinIdle(2);
        config.setMaxWaitMillis(10000);
        pool = new JedisPool(config, Constant.REDIS_HOST);
        
    }
    
    public static Jedis getRedisClient() {
        Jedis jedis = pool.getResource();
        jedis.select(4);
        return jedis;
    }
}
